<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改问题管理')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-problem-edit" th:object="${problem}">
            <h4 class="form-header h4">问卷信息</h4>
            <div class="form-group">
                <label class="col-sm-3 control-label">所属问卷：</label>
                <div class="col-sm-8">
                    <select name="questionId" class="form-control m-b" th:with="type=${@dict.getSelectList('question')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{questionId}"></option>
                    </select>
                </div>
            </div>
            <h4 class="form-header h4">问题管理信息</h4>
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">
                <label class="col-sm-3 control-label">问题类型：</label>
                <div class="col-sm-8">
                    <select name="type" class="form-control m-b" th:with="type=${@dict.getType('question_type')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{type}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">问题序号：</label>
                <div class="col-sm-8">
                    <input name="titleOrder" th:field="*{titleOrder}" class="form-control" type="number">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">问题题目：</label>
                <div class="col-sm-8">
                    <input name="title" th:field="*{title}" class="form-control" type="text">
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">问题得分：</label>
                <div class="col-sm-8">
                    <input name="score" th:field="*{score}" class="form-control" type="number">
                </div>
            </div>
          <!--  <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <input name="remark" th:field="*{remark}" class="form-control" type="text">
                </div>
            </div>-->

            <h4 class="form-header h4">问题答案选项信息</h4>
            <div class="row">
                <div class="col-sm-12">
                    <button type="button" class="btn btn-white btn-sm" onclick="addRow()"><i class="fa fa-plus"> 增加</i></button>
                    <button type="button" class="btn btn-white btn-sm" onclick="sub.delRow()"><i class="fa fa-minus"> 删除</i></button>
                    <div class="col-sm-12 select-table table-striped">
                        <table id="bootstrap-table"></table>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "ask/problem";
        var isAnswerDatas = [[${@dict.getType('is_answer')}]];
        $("#form-problem-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-problem-edit').serialize());
            }
        }

        $(function() {
            var options = {
                data: [[${problem.answerList}]],
                pagination: false,
                showSearch: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                sidePagination: "client",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'index',
                    align: 'center',
                    title: "序号",
                    formatter: function (value, row, index) {
                    	var columnIndex = $.common.sprintf("<input type='hidden' name='index' value='%s'>", $.table.serialNumber(index));
                    	return columnIndex + $.table.serialNumber(index);
                    }
                },
                {
                    field: 'title',
                    align: 'center',
                    title: '选项内容',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='answerList[%s].title' value='%s'>", index, value);
                        return html;
                    }
                },
/*
                {
                    field: 'score',
                    align: 'center',
                    title: '选项得分',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='answerList[%s].score' value='%s'>", index, value);
                        return html;
                    }
                },*/

                {
                    field: 'titleOrder',
                    align: 'center',
                    title: '选项序号',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='number' name='answerList[%s].titleOrder' value='%s'>", index, value);
                        return html;
                    }
                },

                {
                    field: 'isAnswer',
                    align: 'center',
                    title: '是否是答案',
                    formatter: function(value, row, index) {
                        var name = $.common.sprintf("answerList[%s].isAnswer", index);
                        return $.common.dictToSelect(isAnswerDatas, value, name);
                    }
                },
                {
                    field: 'answerParse',
                    align: 'center',
                    title: '答案解析',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='answerList[%s].answerParse' value='%s'>", index, value);
                        return html;
                    }
                },

              /*  {
                    field: 'remark',
                    align: 'center',
                    title: '备注',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='answerList[%s].remark' value='%s'>", index, value);
                        return html;
                    }
                },
*/
                /*{
                    field: 'createTime',
                    align: 'center',
                    title: '创建时间',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='answerList[%s].createTime' value='%s'>", index, value);
                        return html;
                    }
                },

                {
                    field: 'createBy',
                    align: 'center',
                    title: '创建人',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='answerList[%s].createBy' value='%s'>", index, value);
                        return html;
                    }
                },

                {
                    field: 'updateTime',
                    align: 'center',
                    title: '修改时间',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='answerList[%s].updateTime' value='%s'>", index, value);
                        return html;
                    }
                },

                {
                    field: 'updateBy',
                    align: 'center',
                    title: '修改人',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='answerList[%s].updateBy' value='%s'>", index, value);
                        return html;
                    }
                },

                {
                    field: 'deleteFlg',
                    align: 'center',
                    title: '删除标志；0：否 1：是',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='answerList[%s].deleteFlg' value='%s'>", index, value);
                        return html;
                    }
                },*/

                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var value = $.common.isNotEmpty(row.index) ? row.index : $.table.serialNumber(index);
                        return '<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="sub.delRowByIndex(\'' + value + '\')"><i class="fa fa-remove"></i>删除</a>';
                    }
                }]
            };
            $.table.init(options);
        });

        function addRow() {
            var count = $("#" + table.options.id).bootstrapTable('getData').length;
            var row = {
                index: $.table.serialNumber(count),
                title: "",
                score: "",
                titleOrder: "",
                isAnswer: "",
                answerParse: "",
                remark: "",
                createTime: "",
                createBy: "",
                updateTime: "",
                updateBy: "",
                deleteFlg: "",
            }
            sub.addRow(row);
        }
    </script>
</body>
</html>